<template>
  <z-chart v-if="option" class="z-chart z-line-chart" :option="option" />
</template>

<script>
import {baseChartMixin} from "@/zpkgs/components/z-chart/mixins";

// 随机函数
function randomValue() {
  return Math.round(Math.random() * 1000);
}

var dataList=[
  {name:"南海诸岛",value:0},
  {name: '北京', value: randomValue()},
  {name: '天津', value: randomValue()},
  {name: '上海', value: randomValue()},
  {name: '重庆', value: randomValue()},
  {name: '河北', value: randomValue()},
  {name: '河南', value: randomValue()},
  {name: '云南', value: randomValue()},
  {name: '辽宁', value: randomValue()},
  {name: '黑龙江', value: randomValue()},
  {name: '湖南', value: randomValue()},
  {name: '安徽', value: randomValue()},
  {name: '山东', value: randomValue()},
  {name: '新疆', value: randomValue()},
  {name: '江苏', value: randomValue()},
  {name: '浙江', value: randomValue()},
  {name: '江西', value: randomValue()},
  {name: '湖北', value: randomValue()},
  {name: '广西', value: randomValue()},
  {name: '甘肃', value: randomValue()},
  {name: '山西', value: randomValue()},
  {name: '内蒙古', value: randomValue()},
  {name: '陕西', value: randomValue()},
  {name: '吉林', value: randomValue()},
  {name: '福建', value: randomValue()},
  {name: '贵州', value: randomValue()},
  {name: '广东', value: randomValue()},
  {name: '青海', value: randomValue()},
  {name: '西藏', value: randomValue()},
  {name: '四川', value: randomValue()},
  {name: '宁夏', value: randomValue()},
  {name: '海南', value: randomValue()},
  {name: '台湾', value: randomValue()},
  {name: '香港', value: randomValue()},
  {name: '澳门', value: randomValue()}
]

export default {
  name: "ZMapChart",
  props: {
    mapName: String
  },
  mixins: [
      baseChartMixin
  ],
  watch: {
    def: {
      immediate: true,
      handler(o) {
        let records = o.rows
        let columns = o.columns


        this.option = this.$_genMapOption(records, columns, {
          type: 'bar'
        })
      }
    },
  },
  methods: {
    $_genMapOption(records = [], columns = [], options = {}) {
      console.log(records, columns,)
      let ret = {
        visualMap: {
          min: 0,
          max: 1500,
          left: 'left',
          top: 'bottom',
          text: ['高','低'],//取值范围的文字
          inRange: {
            color: ['#fff', '#048ac7']//取值范围的颜色
          },
          show:true//图注
        },
        geo: {
          map: this.mapName,//这里的名称需要和china.js: echarts.registerMap('china',{})中的名称一致
          label: { show: true }, //显示省份
          roam: true, //缩放
          itemStyle: {
            normal:{
              borderColor: 'rgba(0, 0, 0, 0.2)'
            },
            emphasis:{
              areaColor: '#F3B329',//鼠标选择区域颜色
              shadowOffsetX: 0,
              shadowOffsetY: 0,
              shadowBlur: 20,
              borderWidth: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        },
        series: [
          {
            type: 'map',
            label: {
              show: true
            },
            geoIndex: 0,
            data: records.map(v => {
              return {
                name: v[0],
                value: v[1],
              }
            }),
          }
        ], //地图上二开点线特效数组，按需添加
      }
      return ret;
    }
  },
  data() {
    return {
      option:{
      }
    }
  }
}
</script>

<style scoped>

</style>
